package com.xq.shop.controller;

import com.xq.shop.dto.IntegerDto;
import com.xq.shop.dto.TimeDto;
import com.xq.shop.service.IOrderService;
import com.xq.shop.vo.HomeDataVo;
import com.xq.shop.vo.TransactionVo;
import com.xq.shop.vo.WebUserAnalysis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.BaseResult;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author gaoxiaojin
 */
@RestController
@RequestMapping("/home/page")
public class HomePageController {

    private final IOrderService orderService;

    @Autowired
    public HomePageController(IOrderService orderService) {
        this.orderService = orderService;
    }

    @RequestMapping("/getData")
    public BaseResult<HomeDataVo> getData() {
        BaseResult<HomeDataVo> result = new BaseResult<>();
        HomeDataVo vo = orderService.getData();
        result.initializeSuccess(vo);
        return result;
    }

    @RequestMapping("/getOrderCount")
    public BaseResult<List<BigDecimal>> getOrderCount(@RequestBody @Validated IntegerDto dto) {
        BaseResult<List<BigDecimal>> result = new BaseResult<>();
        List<BigDecimal> vo = orderService.getOrderCount(dto);
        result.initializeSuccess(vo);
        return result;
    }

    @RequestMapping("/getPvOrUv")
    public BaseResult<Map<String, List<Integer>>> getPvOrUv() {
        BaseResult<Map<String, List<Integer>>> result = new BaseResult<>();
        Map<String, List<Integer>> map = orderService.getPvOrUv();
        result.initializeSuccess(map);
        return result;
    }

    @RequestMapping("/getPvOrUvByTime")
    public BaseResult<Map<String, List<Integer>>> getPvOrUvByTime(@RequestBody @Validated TimeDto dto) {
        BaseResult<Map<String, List<Integer>>> result = new BaseResult<>();
        Map<String, List<Integer>> map = orderService.getPvOrUvByTime(dto);
        result.initializeSuccess(map);
        return result;
    }

    @RequestMapping("/getWebUserAnalysis")
    public BaseResult<WebUserAnalysis> getWebUserAnalysis(@RequestBody @Validated TimeDto dto) {
        BaseResult<WebUserAnalysis> result = new BaseResult<>();
        WebUserAnalysis webUserAnalysis = orderService.getWebUserAnalysis(dto);
        result.initializeSuccess(webUserAnalysis);
        return result;
    }

    @RequestMapping("/getTransactionAnalysis")
    public BaseResult<TransactionVo> getTransactionAnalysis(@RequestBody @Validated TimeDto dto) {
        BaseResult<TransactionVo> result = new BaseResult<>();
        TransactionVo transactionVo = orderService.getTransactionAnalysis(dto);
        result.initializeSuccess(transactionVo);
        return result;
    }

}
